package com.yugao.fintech.antelope.pay.paytest;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.yugao.fintech.antelope.pay.websocket.WsPayOrderServer;
import com.yugao.fintech.framework.core.response.Resp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
@RestController
@RequestMapping("/test/payNotify")
public class PayTestNotifyController {
    private static final AtomicInteger count = new AtomicInteger(0);

    @PostMapping()
    public String process(@RequestParam Map<String, String> data) {
        log.info("收到支付通知: {}", JSON.toJSONString(data));
        String payOrderNo = data.get("payOrderNo");

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", data.get("status"));
        jsonObject.put("errCode", data.get("errCode"));
        jsonObject.put("payOrderNo", payOrderNo);

        WsPayOrderServer.sendMsgByOrderNo(payOrderNo, Resp.ok(jsonObject));
        return "SUCCESS";
    }
}
